--Nina.as
--An InDesign CS AppleScript
-- Wicej informacji o ksztatach NINA znale mona na stronie:
--http://www.washington.edu/bibsys/mattf/nina/index.html
tell application "Adobe InDesign CS2"
if (count documents) > 0 then
if (class of active window is layout window) then
set myOldXUnits to horizontal measurement units of view preferences of active document
set myOldYUnits to vertical measurement units of view preferences of active document
set horizontal measurement units of view preferences of active document to points
set vertical measurement units of view preferences of active document to points
my myDisplayDialog()
set horizontal measurement units of view preferences of active document to myOldXUnits
set vertical measurement units of view preferences of active document to myOldYUnits
end if
end if
end tell
on myDrawNina(myNumberOfLines, a_pulse, b_pulse, myLength, myClosedPath)
set myList to {}
repeat with myCounter from 0 to (myNumberOfLines * 2)
-- Uwaga: wyraenie "*(180/pi)" konwertuje radiany na stopnie,
-- poniewa funkcje sine/cosine wymagaj podania danych wejciowych
-- w tych wanie jednostkach.
set myAValue to ((-2 * pi * a_pulse * myCounter) / myNumberOfLines) * (180 / pi)
set myBValue to ((-2 * pi * b_pulse * myCounter) / myNumberOfLines) * (180 / pi)
set myASine to my sine_of(myAValue)
set myACosine to my cosine_of(myAValue)
set myBSine to my sine_of(myBValue)
set myBCosine to my cosine_of(myBValue)
set myX to (myACosine + myBCosine) * myLength
set myY to (myASine + myBSine) * myLength
copy {myX, myY} to end of myList
end repeat
tell application "Adobe InDesign CS2"
tell active page of active window
set myGraphicLine to make graphic line
set entire path of path 1 of myGraphicLine to myList
if myClosedPath is true then
set path type of path 1 of myGraphicLine to closed path
else
set path type of path 1 of myGraphicLine to open path
end if
end tell
end tell
end myDrawNina
-- funkcje Sine i Cosine ze zbioru Essential Subroutines Apple'a
on sine_of(x)
repeat until x is greater than or equal to 0 and x < 360
if x is greater than or equal to 360 then
set x to x - 360
end if
if x < 0 then
set x to x + 360
end if
end repeat
-- konwertujemy jednostki ze stopni na radiany
set x to x * (2 * pi) / 360
set answer to 0
set numerator to x
set denominator to 1
set factor to -(x ^ 2)
repeat with i from 3 to 40 by 2
set answer to answer + numerator / denominator
set numerator to numerator * factor
set denominator to denominator * i * (i - 1)
end repeat
return answer
end sine_of
on cosine_of(x)
repeat until x is greater than or equal to 0 and x < 360
if x is greater than or equal to 360 then
set x to x - 360
end if
if x < 0 then
set x to x + 360
end if
end repeat
-- konwertujemy jednostki ze stopni na radiany
set x to x * (2 * pi) / 360
set answer to 0
set numerator to 1
set denominator to 1
set factor to -(x ^ 2)
repeat with i from 2 to 40 by 2
set answer to answer + numerator / denominator
set numerator to numerator * factor
set denominator to denominator * i * (i - 1)
end repeat
return answer
end cosine_of
on myDisplayDialog()
tell application "Adobe InDesign CS2"
set myDialog to make dialog with properties {name:"NINA"}
tell myDialog
-- Dodajemy kolumn okna dialogowego.
tell (make dialog column)
tell (make border panel)
tell (make dialog column)
make static text with properties {static label:"Iterations:"}
make static text with properties {static label:"a_pulse:"}
make static text with properties {static label:"b_pulse:"}
make static text with properties {static label:"Line Length:"}
end tell
tell (make dialog column)
-- Poniszy wiersz prezentuje definiowanie wielu waciwoci tworzonego obiektu.
-- Parametry 201:16:161:72 pozwalaj utworzy adny ksztat NINA
set myNumberOfLinesField to make integer editbox with properties {edit value:201, min width:60}
set myAPulseField to make integer editbox with properties {edit value:16, min width:60}
set myBPulseField to make integer editbox with properties {edit value:161, min width:60}
set myLengthField to make measurement editbox with properties {edit value:72, min width:60, edit units:points}
end tell
end tell
tell (make border panel)
tell (make radiobutton group)
set myClosedPathButton to make radiobutton control with properties {static label:"Closed path", checked state:true}
make radiobutton controls with properties {static label:"Open path"}
end tell
end tell
end tell
end tell
set myReturn to show myDialog
if myReturn is true then
-- Pobieramy wartoci z pl okna dialogowego
set myNumberOfLines to edit value of myNumberOfLinesField
set a_pulse to edit value of myAPulseField
set b_pulse to edit value of myBPulseField
set myLength to edit value of myLengthField
set myClosedPath to checked state of myClosedPathButton
destroy myDialog
my myDrawNina(myNumberOfLines, a_pulse, b_pulse, myLength, myClosedPath)
else
destroy myDialog
end if
end tell
end myDisplayDialog